package net.sangpil.applications.project.architecture.Building3DViewerWithFlv
{
	import flash.display.Bitmap;
	import flash.events.EventDispatcher;
	import flash.geom.Point;
	
	import net.sangpil.classes.events.SimpleLoaderEvent;
	import net.sangpil.classes.net.SimpleLoader;
	
	[Event(name = "positionLoaded", type = "net.sangpil.applications.project.architecture.Building3DViewerWithFlv.GetCatchPositionEvent")]
	public class GetCatchPosition extends EventDispatcher
	{
		private var sl:SimpleLoader;
		private var mode:String;
		private var idx:uint;
		
		public function GetCatchPosition()
		{
			super();
		}
		
		public function load(url:String, mode:String, idx:uint):void
		{
			this.mode = mode;
			this.idx = idx;
			this.sl = new SimpleLoader();
			this.sl.addEventListener(SimpleLoaderEvent.COMPLETED, onLoad);
			this.sl.load(url);
		}
		
		private function onLoad(e:SimpleLoaderEvent):void
		{
			var bt:Bitmap = e.content as Bitmap;
			//trace("GetCatchPosition : " + bt.width, bt.height);
			var posArr:Array = [];
			
			for(var i:uint = 0; i < bt.height; i++)
			{
				for(var j:uint = 0; j < bt.width; j++)
				{
					if(bt.bitmapData.getPixel(j, i) == 0)
					{
						
						var point:Point = new Point(j, i);
						posArr.push(point);
					}
				}
			}
			this.dispatchEvent(new GetCatchPositionEvent(posArr, this.mode, this.idx, GetCatchPositionEvent.POSITION_LOADED));
		}
		
		
		
	}
}